package dao

import "encoding/json"

type RoleUserRelation struct {
	BaseModel
	UserId    int
	RoleId    int
	CompanyId int
}

func (c *RoleUserRelation) TableName() string {
	return "role_user_relation"
}

func (c *RoleUserRelation) ToJsonStr() string {
	marshal, err := json.Marshal(c)
	if err != nil {
		return ""
	}
	return string(marshal)
}

func SelectAllRoleUserRelation() *[]RoleUserRelation {
	roleUserRela := make([]RoleUserRelation, 0)
	DB.Where("is_del = ?", 0).Find(&roleUserRela)
	return &roleUserRela
}

func SelectRoleUserRelationByExample(roleUserRela *RoleUserRelation) *[]RoleUserRelation {
	roleUserRelas := make([]RoleUserRelation, 0)
	DB.Where(&roleUserRela)
	DB.Find(&roleUserRelas)
	return &roleUserRelas
}

func SaveRoleUserRelation(roleUserRela *RoleUserRelation) int {
	DB.Create(&roleUserRela)
	return roleUserRela.ID
}

func SaveRoleUserRelationBatch(roleUserRelas *[]RoleUserRelation) {
	for _, roleUserRela := range *roleUserRelas {
		DB.Create(&roleUserRela)
	}
}

func UpdateRoleUserRelation(roleUserRela *RoleUserRelation) {
	DB.Model(&roleUserRela).Save(&roleUserRela)
}

func DeleteRoleUserRelation(id int) {
	roleUserRela := RoleUserRelation{}
	roleUserRela.ID = id
	DB.Delete(roleUserRela)
}

func DeleteRoleUserRelationByExample(roleUserRela *RoleUserRelation) {
	DB.Where(&roleUserRela).Delete(RoleUserRelation{})
}
